using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;
using TDV.Controles.Base;
using SCHD;
using System.Net.Mail;
using BaseDatos.Comun;
using BaseDatos;
using Aplicacion.Base.WinForm;
using System.Collections;
using System.Data.OleDb;

namespace SCHD
{
    public partial class WFOCSInventory : TDV.Controles.Base.WinForm.BaseForm_Tipo03
    {
        public WFOCSInventory()
        {
            InitializeComponent();
        }

        //private TabControl tabCtrl;
        //private TabPage tabPag;
        //public TabPage TabPag
        //{
        //    get
        //    {
        //        return tabPag;
        //    }
        //    set
        //    {
        //        tabPag = value;
        //    }
        //}
        //public TabControl TabCtrl
        //{
        //    set
        //    {
        //        tabCtrl = value;
        //    }
        //}

       
        private void WFOCSInventory_Load(object sender, EventArgs e)
        {
              // establece el motor de conexion, usuario y base de datos a utilizar
         

       }
        public  void coneccion(string sql)
        {
          
            System.Data.Odbc.OdbcConnection conexion = new OdbcConnection();
            conexion.ConnectionString = "Driver={MySQL ODBC 5.1 Driver};Server=131.107.39.55;Database=ocsweb; User=root;Password=superman;Option=3;";
            conexion.Open();
            System.Data.Odbc.OdbcCommand comando = new OdbcCommand();
            if (rdUser.Checked)
            {
                sql = "Select*from hardware where upper(userid)like '%" + TxtBuscar.Text.ToUpper() + "%'";
            }
            if (rdCPU.Checked)
            {
                sql = "Select*from hardware where upper(name) like '%" + TxtBuscar.Text.ToUpper() + "%'";
            }
            if (rdIP.Checked)
            {
                sql = "Select*from hardware where upper(IPADDR)like '%" + TxtBuscar.Text.ToUpper() + "%'";
            }
            if (rdKeyProd.Checked)
            {
                sql = "Select*from hardware where upper(winprodkey)like '%" + TxtBuscar.Text.ToUpper() + "%'";
            }
            if (rdidSO.Checked)
            {
                sql = "Select*from hardware where upper(osname)like '%" + TxtBuscar.Text.ToUpper() + "%'";
            }
            comando.CommandText = sql;
            comando.Connection = conexion;
            OdbcDataAdapter da = new OdbcDataAdapter(sql,conexion);
            DataSet ds = new DataSet();
            da.Fill(ds,"hardware");
            if (ds.Tables[0].Rows.Count > 0)
            {
                dgOCSEquipo_.DataSource = ds.Tables[0];
                MensajeBarraEstado("Se encontraron " + ds.Tables[0].Rows.Count.ToString() + " Registros");
            }
            else
            {
               
                dgOCSEquipo_.DataSource = null;
                dgMemorias.DataSource = null;
                dgDetalleSoft.DataSource = null;
                dgDetalleSoft.Refresh();
                dgMemorias.Refresh();
            }
        }

        private void btnBuscar_Click(object sender, EventArgs e)
        {
            TxtFabricante.Text = " ";
            TxtModelo.Text = " ";
            TxtSerie.Text = " ";
            TxtTipo.Text = " ";
            coneccion(TxtBuscar.Text);
        }

        private void btnSalir_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void dgOCSEquipo__SelectionChanged(object sender, EventArgs e)
        {
            System.Data.Odbc.OdbcConnection conexion = new OdbcConnection();
            conexion.ConnectionString = "Driver={MySQL ODBC 5.1 Driver};Server=131.107.39.55;Database=ocsweb; User=root;Password=superman;Option=3;";
            conexion.Open();
            System.Data.Odbc.OdbcCommand comando = new OdbcCommand();
            string sql = "Select*from softwares  where  upper(HARDWARE_ID)='" + dgOCSEquipo_.CurrentRow.Cells["ID"].Value.ToString() + "'";
            comando.CommandText = sql;
            comando.Connection = conexion;
            OdbcDataAdapter da = new OdbcDataAdapter(sql, conexion);
            DataSet ds = new DataSet();
            da.Fill(ds, "softwares");
            if (dgOCSEquipo_.Rows.Count > 0)
            {
                dgDetalleSoft.DataSource = ds.Tables[0];
            }
            else
            {
                dgDetalleSoft.DataSource = null;
            }
            System.Data.Odbc.OdbcCommand comando2 = new OdbcCommand();
            string sql2 = "SELECT bios.SMANUFACTURER, bios.SMODEL, bios.HARDWARE_ID, memories.CAPTION, memories.DESCRIPTION, memories.CAPACITY, bios.`TYPE`, memories.SPEED, memories.NUMSLOTS, bios.SSN, bios.`TYPE`, memories.PURPOSE FROM bios , memories where bios.HARDWARE_ID=memories.HARDWARE_ID and  upper(bios.HARDWARE_ID)='" + dgOCSEquipo_.CurrentRow.Cells["ID"].Value.ToString() + "'";
            comando2.CommandText = sql2;
            comando2.Connection = conexion;
            OdbcDataAdapter da2 = new OdbcDataAdapter(sql2, conexion);
            DataSet ds2 = new DataSet();
            da2.Fill(ds2);
            if (ds.Tables[0].Rows.Count>0)
            {
                TxtFabricante.Text = ds2.Tables[0].Rows[0]["SMANUFACTURER"].ToString();
                TxtModelo.Text = ds2.Tables[0].Rows[0]["SMODEL"].ToString();
                TxtSerie.Text = ds2.Tables[0].Rows[0]["SSN"].ToString();
                TxtTipo.Text = ds2.Tables[0].Rows[0]["TYPE"].ToString();
                dgMemorias.DataSource = ds2.Tables[0];
            }
            else
            {
                TxtFabricante.Text = "";
                TxtModelo.Text = "";
                TxtSerie.Text = "";
                TxtTipo.Text = "";
                dgMemorias.DataSource = null;
            }


        }

        private void btnExportar_Click(object sender, EventArgs e)
        {
            dgOCSEquipo_.ExportarDatos();
        }

        private void btnDetalle_Click(object sender, EventArgs e)
        {
            dgDetalleSoft.ExportarDatos();
        }

        private void WFOCSInventory_FormClosing(object sender, FormClosingEventArgs e)
        {
            //tabCtrl.Visible = false;
        }
    }
}

